package top.tocchen.bookshop.controller;

import top.tocchen.bookshop.entity.BookEntity;
import top.tocchen.bookshop.entity.CategoryEntity;
import top.tocchen.bookshop.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @author tocchen
 * @date 2022/8/9 19:34
 * @since jdk 1.8
 **/
@Controller
public class IndexController {
    @Autowired
    SearchService searchService;

    @GetMapping({"/index", "/", "/index.html"})
    public String indexPage(ModelMap map) {
        List<BookEntity> bookList =searchService.findByCategoryId(1);
        List<BookEntity> bookNew = searchService.findBydate();
        List<CategoryEntity> categories = searchService.CategoryfindAll();

        map.addAttribute("books",bookList.subList(0,5));
        map.addAttribute("bookNew",bookNew.subList(0,6));
        map.addAttribute("categories",categories);
        return "index";
    }
}
